<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="import.jsp" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="优质女装...">
    <meta name="keywords" content="女装，服饰...">
    <title>CASEY女装官方网站——重新演绎精湛工艺与优雅皮革</title>
    <style>
        @font-face {
            font-family: 'icomoon';
            src: url('fonts/icomoon.eot?hr7bri');
            src: url('fonts/icomoon.eot?hr7bri#iefix') format('embedded-opentype'),
                url('fonts/icomoon.ttf?hr7bri') format('truetype'),
                url('fonts/icomoon.woff?hr7bri') format('woff'),
                url('fonts/icomoon.svg?hr7bri#icomoon') format('svg');
            font-weight: normal;
            font-style: normal;
            font-display: block;
        }
    </style>
</head>

<link rel="shortcut icon" href="../Imgs/logo.ico" type="image/x-icon">
<link rel="stylesheet" href="../CSS/initialization.css">
<link rel="stylesheet" href="../CSS/productInfoStyle.css">

<body>
<!-- 	获取登录用户用户名 -->
	<%
		request.setCharacterEncoding("UTF-8");
		String username=String.valueOf(session.getAttribute("username"));
		if(username=="null" || username==null){
			request.getRequestDispatcher("message.jsp?content=登录以查看商品详细信息&href=back").forward(request,response);
		}
	%>
	
<!-- 获取商品id -->
	<%	
		String product_id="";
		try{
			product_id=request.getParameter("product_id");
		}catch(Exception e){
			System.out.println("ERROR");
		}
	%>

<!-- 获取商品内容 -->
	<%	
		productMapper productMapper=sqlsession.getMapper(productMapper.class);
		List<product> product=productMapper.selectProductByID(Integer.valueOf(product_id));
		int id=0;String name="";int price=0;int storage=0;int sold=0;int status=0;String kind="";String imgHref1="";String imgHref2="";
		for(product s:product){
			id=s.getProduct_id();name=s.getName().trim();price=s.getPrice();
			storage=s.getStorage();sold=s.getSold();status=s.getStatus();kind=s.getKind().trim();
			List<product_img> product_img=productMapper.selectProductImgById(Integer.valueOf(product_id));
			for(product_img x:product_img){
				imgHref1="../productsImgs/"+kind.toUpperCase()+"/"+x.getImg1()+".jpg";
				imgHref2="../productsImgs/"+kind.toUpperCase()+"/"+x.getImg2()+".jpg";
			}
		}
		
// 		获取某商品被收藏的情况
		likeMapper likeMapper=sqlsession.getMapper(likeMapper.class);
		int temp=Integer.valueOf(product_id);
		List<like> like=likeMapper.selectLikeByUsername(username,temp);
		int like_id=0;
		for(like s:like){
			like_id=s.getLike_id();
		}
	%>

    <!-- 导航栏 -->
    <div class="nav">
        <div class="kindsBox" style="width:400px;">
            <ul>
                   <li><a href="clothePage.jsp">服装系列</a></li>
                    <li><a href="bagPage.jsp">手袋</a></li>
                    <li><a href="otherPage.jsp">配饰</a></li>
            </ul>
        </div>
        <div class="title" onclick="backToHomepage()">CASEY</div>
        <div class="guideBox" style="width:400px;">
            <ul>
                <li><a class="guideBoxA" href="#"><%if(username!=null && username!="null"){out.println("<a href='#' style='font-size:15px;'><span class='icomoon' style='line-height:100%;'></span> &nbsp;"+username+"</a><a href='index.jsp' style='margin-left:20px;'><span class='icomoon'></span></a>");}else{out.println("<a href='index.jsp'><span class='icomoon' style='line-height:100%;''></span> 登录/注册</a>");}%></a></li>
                <li><a href="likePage.jsp">我的收藏</a></li>
                <li><a href="#">购物袋</a></li>
            </ul>
        </div>
    </div>

    <div class="container">
        <div class="box1">
            <span class="icomoon up" style="margin-left:90px;transform:translateY(-200px);"></span>
            <div class="productImgContainer">
                <div class="productImg productImg1" style="background-image:url('<%=imgHref1%>');"></div>
                <div class="productImg productImg2" style="background-image:url('<%=imgHref2%>');"></div>
            </div>
            <span class="icomoon down" style="margin-left:90px;margin-top:-50px;"></span>
        </div>

        <div class="pInfoContainer">
            <div class="info1">
                <span style="width:100%;font-size:22px;margin-bottom:12px;letter-spacing:3px;display:flex;flex-direction:column;" class="name"><%=name%>
                <span class=heartContainer style="transition:all .5s;">
                	<%	
                		if(like_id==0){
                			out.println("<a class='icomoon like1' style='position:absolute;right:-150px;;top:-22px;width:20px;font-size:25px;line-height:18px;'></a><a class='icomoon like2' style='position:absolute;right:-150px;top:-22px;width:20px;font-size:25px;line-height:18px;color:red;opacity:0;'></a></a>");
                		}else{
                			out.println("<a class='icomoon like1' style='position:absolute;right:-150px;top:-22px;width:20px;font-size:25px;line-height:18px;opacity:0;'></a><a class='icomoon like2' style='position:absolute;right:-150px;top:-22px;width:20px;font-size:25px;line-height:18px;color:red;'></a></a>");
                		}
                	%>
               	</span>
                <span style="width:100%;padding-left:10px;letter-spacing:3px;margin-bottom:15px;margin-top:15px;" class="price">￥ <%=price%></span>
                <span style="width:100%;font-size:12px;color:rgb(80,80,80);display:block;margin-top:15px;" class="huabei">-此商品支持花呗分期-</span>
            </div>
            <div class="sizeContainer">
            	<div class="size">
                	SIZE
            	</div>
            	<p>选择最合适您的尺码 :</p>
            	<div id="chooseSize" class="chooseSize">
            		
            	</div>
            	<ul>
            		<li class="size1 size" onClick=chooseSize("M")>M</li>
            		<li class="size2 size" onClick=chooseSize("S")>S</li>
            		<li class="size3 size" onClick=chooseSize("L")>L</li>
            		<li class="size4 size" onClick=chooseSize("XL")>XL</li>
            	</ul>
            </div>
            <span class="storage" style="font-size:13px;margin:10px;margin-left:40px;"><%if(storage>10){out.print("有货");}else if(storage>0){out.print("<font style='color:green'>库存紧张</font>");}else{out.print("<font style='color:red'>缺货</font>");} %><br/><i style="margin-top:15px;font-size:10px;color:rgba(180,180,180)">预计发货后3-7个工作日送达</i></span>
            <button class="addCar" onclick=addToCar()><span >加入购物车</span></button>
            <button class="buyNow" onclick=purchaseNow()><span >立即购买</span></button>
            <span class="consul" style="font-size:13px;"><span class="icomoon" style="font-size:13px;"></span> 17816752712</span>
        </div>
    </div>

    <div class="recommend" style="border:1px solid red;">
        <div class="box box1">
            <p>您可能喜欢</p>
            <p>⭐</p>
            <p>您可能喜欢的相似产品</p>
        </div>
        <div class="box box2"></div>
        <div class="box box3"></div>
        <div class="box box4"></div>
        <div class="box box5"></div>
    </div>

    <div id="footer" class="footer">
        <ul>
            <li class="dt">专属服务</li>
            <li class="dd">免费标准配送</li>
            <li class="dd">免费礼品包装</li>
            <li class="dd" style="margin-bottom:50px;">预约门店服务</li>
            <li class="dt">需要帮助？</li>
            <li class="dd">联系我们</li>
            <li class="dd">常见问题</li>
        </ul>
        <ul>
            <li class="dt">购物帮助</li>
            <li class="dd">支付相关</li>
            <li class="dd">配送</li>
            <li class="dd">退换货</li>
            <li class="dd">发票</li>
            <li class="dd">保养与维修</li>
        </ul>
        <ul>
            <li class="dt">关于公司</li>
            <li class="dd">关于CASEY</li>
            <li class="dd">道德规范</li>
            <li class="dd">职业发展</li>
            <li class="dd">细则与条款</li>
            <li class="dd">隐私与COOKIE</li>
            <li class="dd">企业信息</li>
        </ul>
        <ul>
            <li class="dt">关注CASEY</li>
            <li class="dd">微信</li>
            <li class="dd">抖音</li>
            <li class="dd">腾讯视频</li>
            <li class="dd" style="margin-bottom:50px;">小红书</li>
            <li class="dd">在线顾问</li>
            <li class="dd">17816752712</li>
        </ul>
        <ul>
            <li class="dt">订阅CASEY电子资讯</li>
            <li class="dd">通过订阅，即代表您接受CASEY<em style="color:blue;text-decoration:underline;">隐私政策条款</em></li>
            <li class="dd" style="margin-bottom:50px;"><input type="text" placeholder="电子邮件地址" style="width:200px;">
            </li>
            <li class="dt">直营店查询</li>
            <li class="dd"><input type="text" placeholder="请选择省" style="margin-right:30px;"><input type="text"
                    placeholder="请选择市"></li>
        </ul>
    </div>

</body>

<script>

    var title = document.querySelector(".title");
    var nav = document.querySelector(".nav");
    // 随着滚轮下滑，标题变小
    window.addEventListener('scroll', scroll);
    function scroll() {
        const scrollY = window.scrollY;
        if (scrollY > 0) {
            if (200 - scrollY / 1.5 > 100) {
                title.style.fontSize = 100 - scrollY / 3 + "px";
                nav.style.transform = "translateY(-" + scrollY / 2 + "px)";
            } else {
                nav.style.transform = "";
            }
            if (scrollY > 300) {
                window.onmousewheel = temp;
            } else {
                nav.classList.remove("navSpecial");
                title.classList.remove("titleSpecial");
            }
        } else {
            nav.classList.remove("navSpecial");
            title.classList.remove("titleSpecial");
            nav.classList.add("navSpecialHide");
        }
    }

    // 鼠标滚轮上滑（下滑）显示（隐藏）导航栏
    function temp(e) {
        if (e.wheelDelta) {
            if (window.scrollY > 300) {
                if (e.wheelDelta > 0) {
                    nav.classList.add("navSpecial");
                    title.classList.add("titleSpecial");
                } else {
                    nav.classList.remove("navSpecial");
                    title.classList.remove("titleSpecial");
                }
            }
        }
    }

    var up = document.querySelector(".up");
    var down = document.querySelector(".down");
    var productImg1 = document.querySelector(".productImg1");
    var productImg2 = document.querySelector(".productImg2");
    up.addEventListener("click", function () {
        up.style.transform = "translateY(-100px)";
        down.style.transform = "translateY(0)";
        productImg1.style.transform = "translateY(0)";
        productImg2.style.transform = "translateY(0)";
    });
    down.addEventListener("click", function () {
        up.style.transform = "translateY(0)";
        down.style.transform = "translateY(500px)";
        productImg1.style.transform = "translateY(-100%)";
        productImg2.style.transform = "translateY(-100%)";
    });

//  点击标题返回主页
	function backToHomepage(){
		window.location.href="homePage.jsp";
	}
	
//点击爱心动效
	var heartContainer=document.querySelector(".heartContainer");
	var like1=document.querySelector(".like1");
	var like2=document.querySelector(".like2");
	var status=1;
	var liked=<%=like_id%>;
	if(liked!=0){
		status=-1;
	}
	heartContainer.addEventListener("click",heartAnima);
	function heartAnima(){
		if(status==1){
// 			收藏
			like2.classList.add("heartFull");
			like2.style.opacity=1;
			like1.style.opacity=0;
			status=-1;
			window.location.href="productInfoAction.jsp?content=like&product_id="+<%=product_id%>;
		}else if(status==-1){
// 			取消收藏
			like2.classList.remove("heartFull");
			like2.style.opacity=0;
			like1.style.opacity=1;
			status=1;
			likeOrNot="false";
			window.location.href="productInfoAction.jsp?content=dislike&product_id="+<%=product_id%>;
		}	
	}
	
//设置size
	function chooseSize(size){
		document.querySelector(".chooseSize").innerText=size;
	}
	
// 加入购物车与立即购买按钮的监听事件
	function addToCar(){
		if(document.querySelector('.chooseSize').innerText.length>0){
			window.location.href="productInfoAction.jsp?content=加入购物车&product_id="+<%=product_id%>+"&size="+document.querySelector('.chooseSize').innerText;
		}else{
			alert('请选择商品尺寸');
		}
	}
	
	function purchaseNow(){
		if(document.querySelector('.chooseSize').innerText.length>0){
			window.location.href="productInfoAction.jsp?content=立即购买&product_id="+<%=product_id%>+"&size="+document.querySelector('.chooseSize').innerText;
		}else{
			alert('请选择商品尺寸');
		}
	}
</script>

</html>